/*
 * readline.h
 *
 *  Created on: Jul 28, 2010
 *      Author: Pierre Lindenbaum PhD
 *              plindenbaum@yahoo.fr
 *              http://plindenbaum.blogspot.com
 *              
 */

#ifndef U915_UTIL_RANDOM_H_
#define U915_UTIL_RANDOM_H_


#include <cstdlib>
#include <ctime>

namespace u915 { namespace util {

class Random
	{
	public:
		Random()
		    {

		    }
		virtual ~Random()
		    {

		    }
		virtual double rnd()=0;
		virtual bool nextBool()
		    {
		    return rnd()<0.5;
		    }
		virtual float nextFloat()
		    {
		    return (float)rnd();
		    }
	};

typedef Random* RandomPtr;

class DefaultRandom:public Random
	{
	private:
	    int _rnd()
		{
		return std::rand();
		}
	public:
	    DefaultRandom()
		{
		std::srand(std::time(NULL));
		}
	    DefaultRandom( unsigned int seed)
		{
		std::srand(seed);
		}

	    virtual ~DefaultRandom()
		{
		}

	    virtual double rnd()
		{
		return _rnd()/(double)RAND_MAX;
		}

	};


}}//namespaces

#endif /* TOKENIZER_H_ */
